import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:gt_flutter_admin/services/api_service.dart';
import 'package:gt_flutter_admin/utils/toast_utils.dart';

import '../../../models/page.dart' as gt_page;

class DeptController extends GetxController {
  // 数据
  final Rx<gt_page.Page> deptPage = gt_page.Page().obs;

  // 文本控件
  final TextEditingController usernameText = TextEditingController();

  @override
  void onReady() {
    super.onReady();

    onListDept();
  }

  /// 获取部门列表
  void onListDept() {
    listDept().then((page) => deptPage.value = page);
  }

  /// 删除用户
  void onDeleteDept(num deptId) {
    BrnDialogManager.showConfirmDialog(
      Get.context!,
      title: '是否删除该部门',
      cancel: '取消',
      confirm: '确定',
      onConfirm: () {
        deleteDept(deptId).then((value) {
          onListDept();
          ToastUtils.success('删除成功');
          Navigator.of(Get.context!).pop();
        });
      },
      onCancel: () => Navigator.of(Get.context!).pop(),
    );
  }
}
